package com.itheima.controller;

import com.itheima.pojo.HmSubjectsTags;
import com.itheima.service.TagsService;
import com.itheima.util.PageResult;
import com.itheima.util.SubjectsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tags")
public class TagsController {
    @Autowired
    private TagsService tagsService;

    //标签添加
    @PostMapping
    public void add(@RequestBody HmSubjectsTags hmSubjectsTags){
        tagsService.add(hmSubjectsTags);
    }

    //标签修改
    @PutMapping("/{id}")
    public void update(@PathVariable Integer id,@RequestBody HmSubjectsTags tags){
        tagsService.update(id,tags);
    }

    //标签列表
    @GetMapping
    public PageResult list(String page, String pagesize, String subjectID, String tagName, Integer state){
        return tagsService.list(page,pagesize,subjectID,tagName,state);
    }

    //标签删除
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
        tagsService.del(id);
    }

    //标签状态
    @PostMapping("/{id}/{state}")
    public void status(@PathVariable Integer id,@PathVariable Integer state){
        tagsService.status(id,state);
    }

    //标签详情
    @GetMapping("/{id}")
    public HmSubjectsTags byId(@PathVariable Integer id){
        return tagsService.byId(id);
    }

    /**
     * 根据学科id查询标签
     */
    @GetMapping("/simple")
    public List<SubjectsResult> findById(Integer subjectID){
        return tagsService.findById(subjectID);
    }
}
